/**
 * Created by Administrator on 2018/6/22.
 */

var points = [
    {'name':'宝兴县', 'pos':[102.82058,30.388173]},
    {'name':'天全县', 'pos':[102.778663,30.063344]},
    {'name':'荥经县', 'pos':[102.853267,29.799434]},
    {'name':'芦山县', 'pos':[102.939033,30.148236]},
    {'name':'汉源县', 'pos':[102.657688,29.349799]},
    {'name':'石棉县', 'pos':[102.365654,29.234244]},
    {'name':'名山区', 'pos':[103.115734,30.0759]},
    {'name':'雨城区', 'pos':[103.039693,30.011103]}

];

function drawBarType(id, data, names, title, style, callback) {
    var xs = data.map(function(d){ return d.name; });
    var colors = ['#3CB371', '#3fa7d3', '#FF6347', '#8B1C62'];
    if(style)colors = ['#d0570e','#34da62','#00e9db','#00c0e9','#eb2100','#eb3600','#d0a00e','#0096f3'];

    var series = names.map(function(n, i){
        return {
            name: n,
            type: 'bar',
            stack: '总量',
            itemStyle: {
                normal: {
                    label: {
                        show: true,
                        position: 'inside',
                        formatter: "{c}%",
                    },
                    color: colors[i]
                }
            },
            data: data.map(function(d){ return d.value[i]; })
        };
    });

    var option = {
        backgroundColor: '#ffffff',
        tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器，坐标轴触发有效
                type: 'shadow', // 默认为直线，可选为：'line' | 'shadow'
                color: '#fafafa'
            }
        },
        title: {
            text: title,
            subtext: ''
        },
        legend: {
            data: names
        },
        calculable: true,
        yAxis: [{
            type: 'category',
            data: xs
        }],
        xAxis: [{
            name: '人数',
            type: 'value'
        }],
        series: series
    };
    cout(option);

    var e = Init3(option, id);
    e.on('click', function(d){
        if(style==1 && callback){
            callback(d.name);
            setTable(d.name, 10);
        }else{
            setTable(d.name, 6);
        }
    });
}


function setTable(region, count){
    var html = "", dts = [];
    count = count || (6 + parseInt(Math.random() * 6));
    var names = ['赵', '钱', '孙', '李', '张', '周', '吴', '郑', '王', '冯'];
    var educations = ["博士后", "海归博士", "博士", "硕士", "本科", "大专", "高中", "中专", "初中", "小学"];
    for(var i=0; i<count; i++){
        var name = names[d(0, names.length)] + "*";
        var education = educations[d(0, educations.length)];
        var work = ['县委', '县人大', '县政府', '县政协'][d(0, 4)];
        region = region || points[parseInt(Math.random() * points.length)].name ;
        html+='<tr class="error"><td>'+ name +'</td><td>'+ education +'</td><td>'+ region +'</td><td>'+ work +'</td></tr>';
    }

    $("#tbody1").html(html);
    $("#node").text(region + " 干部人员详情");
}
